/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MAIN;

import CLIENT.ClientrMainChatFrame;
import GUI.*;
import Server.ServerMainChatFrame;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author Yaniv Kalif
 */
public class ManagerFrame extends JFrame implements WindowListener,ActionListener
{
    StartPanel _startP;
    ServerMainChatFrame _serverF;
    ClientrMainChatFrame _clientF;
    public ManagerFrame()
    {
         this.setResizable(false);//the window size cannot be changed
         //setting the Layout Manager
            BorderLayout layout=new BorderLayout();
            this.getContentPane().setLayout(layout);

         //create a new Start Panel
            _startP = new StartPanel(this);
            this.getContentPane().add(_startP);


        //this.setIconImage(_image3DP);//add the picture as an Frame icon
        this.setTitle("Talk2Me");
        this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
        this.addWindowListener(this);
    }
     public void actionPerformed(ActionEvent e)
    {
         try
         {
                    if(e.getSource()==_startP._createGroup)
                    {

                        this.setVisible(false);
                        int serverPort = Integer.valueOf(_startP._createPortText.getText());
                        _serverF = new ServerMainChatFrame(serverPort);
                        System.out.println("Server Is UP");
                        _serverF.setVisible(true);
                        // need to check if port is ok //
                    }
                    if(e.getSource()==_startP._joinGroup)
                    {
                        this.setVisible(false);
                        _clientF = new ClientrMainChatFrame(_startP._joinIPText.getText(),Integer.parseInt(_startP._joinPortText.getText()));
                        _clientF.setVisible(true);
                    }
         }
         catch (IOException ex)
         {
                Logger.getLogger(ManagerFrame.class.getName()).log(Level.SEVERE, null, ex);
         }
    }
    public void windowOpened(WindowEvent e) {}
    public void windowClosing(WindowEvent e) {System.exit(0);}
    public void windowClosed(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowActivated(WindowEvent e) {}
    public void windowDeactivated(WindowEvent e) {}
   
}
